using AutoMapper;
using ilgolosone.Shared;

namespace ilgolosone.UI.Mappers
{
    public abstract class BaseFormatter<TData> : IValueFormatter
    {
        public string FormatValue(ResolutionContext context)
        {
            if (context.SourceValue == null)
                return null;

            if (!(context.SourceValue is TData))
                return context.SourceValue.ToNullSafeString();

            return FormatValueCore((TData)context.SourceValue);
        }

        protected abstract string FormatValueCore(TData value);
    }
}